<script type="text/javascript">

function delete_drafts() {
    var ids = '';
    selects = $("input[@type=checkbox]:checked");
    selects.each(function() {
        if (this.value != '') {
            ids = ids + this.value + '|';
        }
    });

    if (ids == '') {
        show_noticemessage('<?php __e('No conversations selected.'); ?>');
    } else {
        
        $.getJSON('<?php echo $html->admin_url('/drafts/ajax_drafts/' . $page); ?>/'+ids + '+?time=' + time_now(), function(json_data) {
            window.location.href='<?php echo $html->admin_url('/drafts/drafts/' . $page . '/deleted_done'); ?>';
            return true;
            var tablebar_content = $('.tablebar_content').html();
            selects.each(function() {
                if (this.value != '') {
                    $('.tr_'+this.value).remove();
                }
            });

//            $('.tablebar_content').html(tablebar_content);
            $('#page_link_upper').html(json_data.pagelink);
            $('#page_link_lower').html(json_data.pagelink);
            var msg = '';

            if (json_data.deleted_count != 0) {
                msg = json_data.deleted_count+' <?php __e('conversations have been deleted.'); ?> ';
            } else {
                msg = '<?php __e('No conversations deleted.'); ?>';
            }

            if (json_data.my_drafts_count != 0) {
                $('#drafts_count').html('('+json_data.my_drafts_count+')');
            } else {
                $('#drafts_count').html('');
                $('#list').html('<?php echo '<span class="new">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __('You have no drafts right now!') . '</span>'; ?>');
            }
            show_noticemessage(msg);
        });
    }
}

function change_star(post_id) {
        var star_img;
        var img_url;

        $.get('<?php echo $html->admin_url('/posts/ajax_change_star/'); ?>'+ post_id + '?time=' + time_now(), function(data) {
            if (data == 'on') {
                star_img = 'star_on.gif';
            } else {
                star_img = 'star_off.gif';
            }

            $('#star_img_' + post_id).attr({ 
                src: '<?php echo $html->theme_path('img'); ?>/' + star_img
            });

       });
}

</script>

<div id="content">
<form id="list">
<?php
if(!empty($posts->results)) {
?>
    <table>
    <tr>
    <td colspan="4" class="tablebar"><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td align="left"><span class="tablebar_content"><input value="<?=__('Delete')?>" type="button" onclick="delete_drafts();return false;"></span>
            <td align="right"><span class="page_link" id="page_link_upper"><?=$posts->pagelink?></span></td>
        </tr>
        </table>
    </td>
    </tr>
      <tr>
        <th><input value="" type="checkbox" name="select_all" id="select_all" onclick="mod_allcheckbox_status2( 'post_id[]' , this.checked );"> <?php __e('Title'); ?></th>
        <th><?php __e('Categories'); ?></th>
        <th><?php __e('Author'); ?></th>
        <th><?php __e('When'); ?></th>
      </tr>

<?php
foreach($posts->results as $post) {
    $star_img = $post->star_status ? 'star_on.gif' : 'star_off.gif';
    if (empty($post->post_title)) {
        $post_title =  '(' . __('no title') . ')';
        $style = array('style'=>'color:#999;');
    } else {
        $post_title =  $post->post_title;
        $style = array();
    }
?>
      <tr class="tr_<?php echo $post->id; ?>">
        <td><input value="<?php echo $post->id; ?>" type="checkbox" id="post_id_<?php echo $post->id; ?>" name="post_id[]" onclick="change_allcheckbox_status('post_id[]','select_all');">
        <a id="star<?php echo $post->id; ?>"><?php echo $html->image($star_img,array('id'=>'star_img_' . $post->id, 'onclick'=>"change_star($post->id);")); ?></a>
        <?php echo $html->admin_link(attribute_escape($post_title), '/post_new/post_new/' . $post->id . '/draft', $style); ?></td>
        <td> <?php echo get_category_name($post->category_id) ?> </td>
        <td> <?php echo get_username_by_id($post->poster_id); ?> </td>
        <td> <?php echo time_format($post->post_time); ?></td>
      </tr>
<?php
    }
?>
      <tr>
        <td colspan="4" class="tablebar"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td align="left"><span class="tablebar_content"><input value="<?=__('Delete')?>" type="button" onclick="delete_drafts();return false;"></span>
    </td>
   <td align="right"><span class="page_link" id="page_link_lower"><?=$posts->pagelink?></span></td>
   </tr>

    </table></td>
    </tr>
    </table>
<?php
} else {
?>
<span class="new"><?php __e('You have no drafts right now!'); ?> </new>
<?php
}
?>
  </form>
</div>
